<?php
namespace App\Http\Strategy;

use App\Common\ErrorCode\ErrorCode;
use App\Exceptions\BusinessException;
use App\Http\Service\UserService;
use App\Models\UserStaffModel;

class PersonalStrategy
{
    private $userStaff;

    public function __construct(UserStaffModel $userStaffModel)
    {
        $this->userStaff = $userStaffModel;
    }

    /**
     * 设置员工类型
     * @param $userId
     * @param $cate int 员工类型
     */
    public function setType($userId, $cate)
    {
        $user = $this->userStaff->newQuery()->where(['uid' => $userId])->first();
        if (empty($user)) {
            $this->userStaff->setAttribute('uid', $userId);
            $this->userStaff->setAttribute('cate', $cate);
            $this->userStaff->setAttribute('created_at', time());
            $this->userStaff->save();
        }else{
            $this->userStaff->setAttribute('updated_at', time());
            $user->setAttribute('cate', $cate);
            $user->save();
        }
    }
}